<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 11-10-3
 * Time: PM4:03
 */

include_once '../common.func.php';

$tags = getTags();

$id = intval($_POST['id']);
$name = trim($_POST['name']);

if ($_POST['action'] == '保存') {
    if ($tags[$id]) {
        $tags[$id]['name'] = $name;
        saveTags($tags);
    }
} elseif ($_POST['action'] == '删除') {
    unset($tags[$id]);
    saveTags(array_values($tags));
} elseif ($_POST['action'] == '添加') {
    array_push($tags, array('name' => $name, 'posts' => array()));
    saveTags($tags);
}

header('Location: ' . SITE_URL . '/admin/tag.php');
